﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using VanTaiBLL;
using VanTaiData;
using VanTaiProperty;
using Roles;
using System.Web.UI.HtmlControls;

namespace VanTaiTMS.Page
{
    public partial class nhan_vien : System.Web.UI.Page
    {
        #region[Define]
        private DataTable dtMember;
        private DataTable dtMemberDetailEdit;
        private DataTable dtSearch;
        protected string SuggestionList;
        protected string StrAlert = "";
        private DataTable dtAutoComplete;
        private static bool flag = false;
        private clsTMMemberBusiness clsMember = new clsTMMemberBusiness();
        #endregion

        #region[Controller]
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPermisstion();
            Autocomplate();
            if (!IsPostBack)
            {
                BindGridMember();
                PanelChonSoDienThoai.Visible = false;
                txtSoDienThoai10.Visible = false;
                txtSoDienThoai11.Visible = false;
            }
        }
        protected void cmdAddNew_Click(object sender, EventArgs e)
        {
            flag = true;
            lbThongBaoLoi.Text = "";
            txtMaNhanVien.Enabled = true;
            ClearTextBox();
            OpenDialog("#danhmucnhanvien");
            imgSave.ToolTip = "Thêm mới";
            upNewUpdatePanel.Update();
            imgSave.Visible = true;
        }
        protected void cmdEdit_Click(object sender, EventArgs e)
        {
            lbThongBaoLoi.Text = "";
            txtMaNhanVien.Enabled = false;
            for (int i = 0; i < ListViewAll.Items.Count; i++)
            {
                CheckBox chkView = (CheckBox)ListViewAll.Items[i].FindControl("chkList");
                Label lbTrangThai = (Label)ListViewAll.Items[i].FindControl("lbDuyet");
                if (chkView != null)
                {
                    if (chkView.Checked)
                    {
                        BindGridMemberDetail_Edit(Convert.ToInt32(ListViewAll.DataKeys[i].Value.ToString()));
                        OpenDialog("#danhmucnhanvien");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                }
            }
        }
        protected void cmdDel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewAll.Items.Count; i++)
            {
                CheckBox chkHide = (CheckBox)ListViewAll.Items[i].FindControl("chkList");
                Label lbTrangThai = (Label)ListViewAll.Items[i].FindControl("lbDuyet");
                if (chkHide != null)
                {
                    if (chkHide.Checked)
                    {
                        try
                        {
                            if (clsMember.TMMember_Check_Delete_TMCommandTransferOrder(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false
                                && clsMember.TMMember_Check_Delete_TMDiaryTransferOrder(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false
                                && clsMember.TMMember_Check_Delete_TMPlan_TransferOrder(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false
                                && clsMember.TMMember_Check_Delete_TMSalesReport(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false
                                && clsMember.TMMember_Check_Contract(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false
                                && clsMember.TMMember_Check_User(int.Parse(ListViewAll.DataKeys[i].Value.ToString())) == false)
                            {
                                VanTaiBLL.clsTMMemberBusiness.DeleteTMMember(int.Parse(ListViewAll.DataKeys[i].Value.ToString()));
                                BindGridMember();
                            }
                            else
                            {
                                lbThongBaoXoa.Text = "Mẫu tin này vẩn còn tồn tại.Không thể xoá !";
                                OpenDialog("#thongbaoxoa");
                                upDatePanelThongBaoXoa.Update();
                                cmdAgree.Visible = false;
                                cmdClose.Text = "Đóng lại";
                            }
                        }
                        catch (Exception ex)
                        {
                            lbThongBaoXoa.Text = ex.ToString();
                            OpenDialog("#thongbaoxoa");
                            upDatePanelThongBaoXoa.Update();
                            cmdAgree.Visible = false;
                            cmdClose.Text = "Đóng lại";
                        }
                    }
                }
            }
        }
        protected void cmdSerach_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "")
            {
                StrAlert += "<div class='alert alert-warning'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Vui lòng nhập vào từ khoá để tìm kiếm !";
                StrAlert += "</div>";
            }
            else
            {
                Search(txtSearch.Text);
            }
        }
        protected void cmdRefesh_Click(object sender, EventArgs e)
        {
            txtSearch.Text = "";
            BindGridMember();
        }
        protected void cmdExport_Click(object sender, EventArgs e)
        {
            OpenDialog("#exporttoexcel");
        }
        protected void cmdExportToExcel_Click(object sender, EventArgs e)
        {
        }
        //---------------button-popup---------------------
        protected void imgrefesh_Click(object sender, ImageClickEventArgs e)
        {

        }
        protected void imgSave_Click(object sender, ImageClickEventArgs e)
        {
            if (txtMaNhanVien.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào mã nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtTenNhanVien.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào tên nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtNgaySinh.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào ngày sinh nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (drGioiTinh.SelectedValue.ToString() == "-1")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn giới tính nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (drChonSoDienThoai.SelectedValue.ToString() == "-1")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn số điện thoại !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtEmail.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào địa chỉ Email nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtSoDienThoai10.Text == "" || txtSoDienThoai11.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào số điện thoại nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtSoCMT.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào số chứng minh nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtDiaChi.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng điền vào địa chỉ nhân viên !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtMaNhanVien.Text != "" && txtTenNhanVien.Text != ""
                && txtNgaySinh.Text !="" && drGioiTinh.SelectedValue.ToString() !="-1"
                && drChonSoDienThoai.SelectedValue.ToString() !="-1"
                && txtSoCMT.Text !=""
                && txtSoDienThoai10.Text !="" || txtSoDienThoai11.Text !=""
                && txtDiaChi.Text !="" && txtEmail.Text !="")
            {
                Insert();
            }
        }
        protected void cmdAgree_Click(object sender, EventArgs e)
        {
            
        }
        protected void cmdClose_Click(object sender, EventArgs e)
        {
            CloseDialog("#thongbaoxoa");
        }
        protected void cmdCloseThongBao_Click(object sender, EventArgs e)
        {
            CloseDialog("#thongbao");
        }
        protected void ImgRefeshDuyet_Click(object sender, ImageClickEventArgs e)
        {

        }
        protected void ImgRefeshExport_Click(object sender, ImageClickEventArgs e)
        {
            //txtTuNgayNhapKhoExport.Text = "";
            //txtDenNgayNhapKhoExport.Text = "";
            //BindGridLenhDieuDongExportExcel();
        }
        //-------------list-view-----------------------
        protected void ListViewAll_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            try
            {
                HttpCookie cookie = Request.Cookies["UserLogin"];
                bool Edit = SecurityServices.HasPermisstion(StringContent.QuanLyDanhMucNhanVien, int.Parse(cookie["RolesID"]), TypeaAudit.Edit);
                lbThongBaoLoi.Text = "";
                txtMaNhanVien.Enabled = false;
                if (e.CommandName == "Accept")
                {
                    if (Edit == false)
                    {
                        imgSave.Visible = false;
                        string SenderId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                        BindGridMemberDetail_Edit(int.Parse(SenderId));
                        OpenDialog("#danhmucnhanvien");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                    else
                    {
                        imgSave.Visible = true;
                        string SenderId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                        BindGridMemberDetail_Edit(int.Parse(SenderId));
                        OpenDialog("#danhmucnhanvien");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                }
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        protected void ListViewAll_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LinkButton linkListName = (LinkButton)e.Item.FindControl("linkListName");
                string _jsDouble1 = ClientScript.GetPostBackClientHyperlink(linkListName, "");


                linkListName.Attributes["ondblclick"] = _jsDouble1;
                linkListName.Attributes["onclick"] = "return false;";
            }
        }
        //-----------pagger-----------------------
        protected void DataPagerListAll_PreRender(object sender, EventArgs e)
        {
            DataPagerListAll.PageSize = 17;
            BindGridMember();
        }
        //---------Check-all--------------
        protected void chkCheckAll_CheckedChanged(object sender, EventArgs e)
        {

        }
        //---------Dropdownlist-----------
        protected void drChonSoDienThoai_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (drChonSoDienThoai.SelectedValue.ToString() == "1")
            {
                PanelChonSoDienThoai.Visible = true;
                txtSoDienThoai10.Visible = true;
                txtSoDienThoai11.Visible = false;
            }
            if (drChonSoDienThoai.SelectedValue.ToString() == "2")
            {
                PanelChonSoDienThoai.Visible = true;
                txtSoDienThoai10.Visible = false;
                txtSoDienThoai11.Visible = true;
            }
            if (drChonSoDienThoai.SelectedValue.ToString() == "-1")
            {
                PanelChonSoDienThoai.Visible = false;
                txtSoDienThoai10.Visible = false;
                txtSoDienThoai11.Visible = false;
                txtSoDienThoai10.Text = "";
                txtSoDienThoai11.Text = "";
            }
        }
        #endregion

        #region[Function]
        protected void BindGridMember()
        {
            dtMember = clsMember.Search(txtSearch.Text);
            if (dtMember != null && dtMember.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtMember;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;
            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
            }
        }
        protected void BindGridMemberDetail_Edit(int id)
        {
            dtMemberDetailEdit = clsMember.BindGirdTMMember_Detail_Edit(id);
            if (dtMemberDetailEdit != null && dtMemberDetailEdit.Rows.Count > 0)
            {
                lbID.Text = dtMemberDetailEdit.Rows[0]["Member_ID"].ToString();
                lbIDXoa.Text = dtMemberDetailEdit.Rows[0]["Member_ID"].ToString();
                txtMaNhanVien.Text = dtMemberDetailEdit.Rows[0]["Member_Alias"].ToString();
                txtTenNhanVien.Text = dtMemberDetailEdit.Rows[0]["FullNameMem"].ToString();
                if (dtMemberDetailEdit.Rows[0]["Brith_Mem"] == DBNull.Value)
                {
                    txtNgaySinh.Text = "";
                }
                else
                {
                    txtNgaySinh.Text = dtMemberDetailEdit.Rows[0]["Brith_Mem"].ToString();
                }
                if (dtMemberDetailEdit.Rows[0]["Sex_Mem"] == DBNull.Value)
                {
                    drGioiTinh.SelectedIndex = -1;
                }
                else
                {
                    drGioiTinh.SelectedValue = dtMemberDetailEdit.Rows[0]["Sex_Mem"].ToString();
                }
                if (dtMemberDetailEdit.Rows[0]["PhoneNumber_Mem"] == DBNull.Value)
                {
                    drChonSoDienThoai.SelectedIndex = -1;
                    txtSoDienThoai11.Text = "";
                    txtSoDienThoai10.Text = "";
                }
                if (dtMemberDetailEdit.Rows[0]["PhoneNumber_Mem"].ToString().Length == 14)
                {
                    PanelChonSoDienThoai.Visible = true;
                    txtSoDienThoai10.Visible = true;
                    txtSoDienThoai11.Visible = false;
                    txtSoDienThoai10.Text = dtMemberDetailEdit.Rows[0]["PhoneNumber_Mem"].ToString();
                    drChonSoDienThoai.SelectedValue = "1";
                }

                if (dtMemberDetailEdit.Rows[0]["PhoneNumber_Mem"].ToString().Length == 15)
                {
                    PanelChonSoDienThoai.Visible = true;
                    txtSoDienThoai10.Visible = false;
                    txtSoDienThoai11.Visible = true;
                    txtSoDienThoai11.Text = dtMemberDetailEdit.Rows[0]["PhoneNumber_Mem"].ToString();
                    drChonSoDienThoai.SelectedValue = "2";
                }
                if (dtMemberDetailEdit.Rows[0]["Number_CMT_Mem"] == DBNull.Value)
                {
                    txtSoCMT.Text = "";
                }
                else
                {
                    txtSoCMT.Text = dtMemberDetailEdit.Rows[0]["Number_CMT_Mem"].ToString();
                }
                if (dtMemberDetailEdit.Rows[0]["Address_Mem"] == DBNull.Value)
                {
                    txtDiaChi.Text = "";
                }
                else
                {
                    txtDiaChi.Text = dtMemberDetailEdit.Rows[0]["Address_Mem"].ToString();
                }
                txtGhiChu.Text = dtMemberDetailEdit.Rows[0]["Note_Mem"].ToString();
                txtEmail.Text = dtMemberDetailEdit.Rows[0]["Email_Mem"].ToString();
            }
        }
        protected void Insert()
        {
            //Insert
            if (flag)
            {
                InsertMember();
            }
            else//Update
            {
                UpdateMember();
            }
        }
        protected bool CheckInsert()
        {
            bool kiemtra = false;
            dtMember = clsMember.BindGirdTMMember();
            if (dtMember != null && dtMember.Rows.Count > 0)
            {
                foreach (DataRow dr in dtMember.Rows)
                {
                    if (txtMaNhanVien.Text == dr["Member_Alias"].ToString())
                    {
                        kiemtra = true;
                    }
                }
            }
            return kiemtra;
        }
        protected void InsertMember()
        {
            try
            {
                if (CheckInsert())
                {
                    lbThongBaoLoi.Text = "Mã nhân viên này đã tồn tại !";
                    OpenDialog("#thongbao");
                    updatePanelThongBao.Update();
                }
                else
                {
                    VanTaiProperty.clsTMMemberProperty obj = new clsTMMemberProperty();
                    obj.Member_Alias = txtMaNhanVien.Text;
                    obj.FullNameMem = txtTenNhanVien.Text;
                    obj.Brith_Mem = DateTime.Parse(txtNgaySinh.Text);
                    obj.Sex_Mem = drGioiTinh.SelectedValue.ToString();
                    if (drChonSoDienThoai.SelectedValue == "1")
                    {
                        PanelChonSoDienThoai.Visible = true;
                        txtSoDienThoai10.Visible = true;
                        txtSoDienThoai11.Visible = false;
                        obj.PhoneNumber_Mem = txtSoDienThoai10.Text;
                    }
                    if (drChonSoDienThoai.SelectedValue == "2")
                    {
                        PanelChonSoDienThoai.Visible = true;
                        txtSoDienThoai10.Visible = false;
                        txtSoDienThoai11.Visible = true;
                        obj.PhoneNumber_Mem = txtSoDienThoai11.Text;
                    }
                    obj.Number_CMT_Mem = txtSoCMT.Text;
                    obj.Address_Mem = txtDiaChi.Text;
                    obj.Note_Mem = txtGhiChu.Text;
                    obj.Email_Mem = txtEmail.Text;
                    //------------------
                    obj.FullName_C = DBNull.Value.ToString();
                    obj.FullName_E = DBNull.Value.ToString();
                    obj.Alias_Mem = DBNull.Value.ToString();
                    obj.Household_Mem = DBNull.Value.ToString();
                    obj.PlaceOFBirth_Mem = DBNull.Value.ToString();
                    obj.Origin_Mem = DBNull.Value.ToString();
                    obj.ID_Religion_Mem = 0;
                    obj.ID_Ethnicity_Mem = 0;
                    obj.Number_Car_Mem = DBNull.Value.ToString();
                    obj.Districts_Mem = 0;
                    obj.Id_Province_Mem = 0;
                    obj.ID_Domain_Mem = 0;
                    obj.Id_National_Mem = 0;
                    obj.Img_Mem = DBNull.Value.ToString();
                    obj.MaCha = DBNull.Value.ToString();
                    VanTaiBLL.clsTMMemberBusiness.InsertTMMember(obj);
                    lbThongBaoLoi.Text = "Thêm mẫu tin thành công !";
                    OpenDialog("#thongbao");
                    updatePanelThongBao.Update();
                    BindGridMember();
                    ClearTextBox();
                }
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        protected void UpdateMember()
        {
            try
            {
                VanTaiProperty.clsTMMemberProperty obj = new clsTMMemberProperty();
                obj.Member_ID = int.Parse(lbID.Text);
                obj.Member_Alias = txtMaNhanVien.Text;
                obj.FullNameMem = txtTenNhanVien.Text;
                obj.Brith_Mem = DateTime.Parse(txtNgaySinh.Text);
                obj.Sex_Mem = drGioiTinh.SelectedValue.ToString();
                if (drChonSoDienThoai.SelectedValue == "1")
                {
                    PanelChonSoDienThoai.Visible = true;
                    txtSoDienThoai10.Visible = true;
                    txtSoDienThoai11.Visible = false;
                    obj.PhoneNumber_Mem = txtSoDienThoai10.Text;
                }
                if (drChonSoDienThoai.SelectedValue == "2")
                {
                    PanelChonSoDienThoai.Visible = true;
                    txtSoDienThoai10.Visible = false;
                    txtSoDienThoai11.Visible = true;
                    obj.PhoneNumber_Mem = txtSoDienThoai11.Text;
                }
                obj.Number_CMT_Mem = txtSoCMT.Text;
                obj.Address_Mem = txtDiaChi.Text;
                obj.Note_Mem = txtGhiChu.Text;
                obj.Email_Mem = txtEmail.Text;
                //------------------
                obj.FullName_C = DBNull.Value.ToString();
                obj.FullName_E = DBNull.Value.ToString();
                obj.Alias_Mem = DBNull.Value.ToString();
                obj.Household_Mem = DBNull.Value.ToString();
                obj.PlaceOFBirth_Mem = DBNull.Value.ToString();
                obj.Origin_Mem = DBNull.Value.ToString();
                obj.ID_Religion_Mem = 0;
                obj.ID_Ethnicity_Mem = 0;
                obj.Number_Car_Mem = DBNull.Value.ToString();
                obj.Districts_Mem = 0;
                obj.Id_Province_Mem = 0;
                obj.ID_Domain_Mem = 0;
                obj.Id_National_Mem = 0;
                obj.Img_Mem = DBNull.Value.ToString();
                obj.MaCha = DBNull.Value.ToString();
                VanTaiBLL.clsTMMemberBusiness.UpdateTMMember(obj);
                lbThongBaoLoi.Text = "Cập nhật mẫu tin thành công !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
                BindGridMember();
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        //AutoComplate
        protected void Autocomplate()
        {
            dtAutoComplete = clsMember.BindGirdTMMember();
            if (dtAutoComplete != null && dtAutoComplete.Rows.Count > 0)
            {
                foreach (DataRow dr in dtAutoComplete.Rows)
                {
                    if (string.IsNullOrEmpty(SuggestionList))
                    {
                        SuggestionList += "\"" + dr["Member_Alias"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Address_Mem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["PhoneNumber_Mem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Number_CMT_Mem"].ToString().Replace("\n", " ") + "\",";
                    }
                    else
                    {
                        SuggestionList += "\"" + dr["Member_Alias"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Address_Mem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["PhoneNumber_Mem"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Number_CMT_Mem"].ToString().Replace("\n", " ") + "\",";
                    }
                }
            }
        }
        protected void Search(string keywords)
        {
            dtSearch = clsMember.Search(keywords);
            if (dtSearch != null && dtSearch.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtSearch;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

                StrAlert += "<div class='alert alert-success'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Tìm thấy " + dtSearch.Rows.Count.ToString() + " mẫu tin !";
                StrAlert += "</div>";
            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
                StrAlert += "<div class='alert alert-error'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Không tìm thấy mẫu tin nào !";
                StrAlert += "</div>";
            }
        }
        //Total
        #endregion

        #region[OpenDialog]
        private void OpenDialog(string dialogId)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("$('" + dialogId + "').dialog('open');");
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
               "scriptKey", sb.ToString(), true);
        }
        private void CloseDialog(string dialogId)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("$('" + dialogId + "').dialog('close');");
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
               "scriptKey", sb.ToString(), true);
        }
        #endregion

        #region[Clear-TextBox]
        protected void ClearTextBox()
        {
            txtMaNhanVien.Text = "";
            txtTenNhanVien.Text = "";
            txtNgaySinh.Text = "";
            drGioiTinh.SelectedIndex = -1;
            drChonSoDienThoai.SelectedIndex = -1;
            txtSoDienThoai10.Text = "";
            txtSoDienThoai11.Text = "";
            txtSoCMT.Text = "";
            txtDiaChi.Text = "";
            txtGhiChu.Text = "";
        }
        #endregion

        #region[Permisstion]
        protected void CheckPermisstion()
        {
            HttpCookie cookie = Request.Cookies["UserLogin"];
            if (cookie != null)
            {
                bool Is_Page_All = SecurityServices.HasPermisstionPage(StringContent.QuanLyDanhMucNhanVien, int.Parse(cookie["RolesID"]), true);
                if (Is_Page_All == true)
                {
                    bool AddNew = SecurityServices.HasPermisstion(StringContent.QuanLyDanhMucNhanVien, int.Parse(cookie["RolesID"]), TypeaAudit.AddNew);
                    if (AddNew == false)
                    {
                        cmdAddNew.Visible = false;
                    }
                    else
                    {
                        cmdAddNew.Visible = true;
                    }
                    bool Edit = SecurityServices.HasPermisstion(StringContent.QuanLyDanhMucNhanVien, int.Parse(cookie["RolesID"]), TypeaAudit.Edit);
                    if (Edit == false)
                    {
                        cmdEdit.Visible = false;
                    }
                    else
                    {
                        cmdEdit.Visible = true;
                    }
                    bool Del = SecurityServices.HasPermisstion(StringContent.QuanLyDanhMucNhanVien, int.Parse(cookie["RolesID"]), TypeaAudit.Delete);
                    if (Del == false)
                    {
                        cmdDel.Visible = false;
                    }
                    else
                    {
                        cmdDel.Visible = true;
                    }
                }
                else
                {
                    Response.Redirect("error-page.aspx");
                }
            }
        }
        #endregion
    }
}